{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 1. Visualizations, Part 2" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this notebook, we continue to look at methods of displaying information visually. See [Part 1](Visualization.ipynb)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#Table of Contents\n", "* [1. Visualizations, Part 2](#1.-Visualizations,-Part-2)\n", "\t* [1.1 Preliminaries](#1.1-Preliminaries)\n", "\t\t* [1.1.1 Arrays](#1.1.1-Arrays)\n", "\t* [1.2 Albers Conic Map Projection](#1.2-Albers-Conic-Map-Projection)\n", "\t* [1.3 Genomics](#1.3-Genomics)\n", "\t* [1.4 Relationships](#1.4-Relationships)\n", "\t* [1.5 Heatmaps](#1.5-Heatmaps)\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1.1 Preliminaries" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To explore these ideas, we need to introduce a new construct in Processing: the array." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### 1.1.1 Arrays" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Arrays are contiguous blocks of memory used to store similar things. Effectively this allows you to have variables that you can reference by a number.\n", "\n", "You can define a variable to hold an unspecified number of integers with:\n", "\n", "```java\n", "int [] values = new int[] { 1, 2, 3 };\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can also assign the variable with an array of values at the same time. We use the `new` keyword to create the array that holds the elements 1, 2, and 3:\n", "\n", "\n", "```java\n", "int [] values = new int[] { 1, 2, 3 };\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To refer to the first and second items, we use:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "```java\n", "values[0]\n", "values[i]\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's see the array in use." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## 1.2 Albers Conic Map Projection" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In the last lecture, we used a SVG image of the united states.\n", "\n", "Here, we use a meta-command to download the file again:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%download http://upload.wikimedia.org/wikipedia/commons/archive/3/32/20091105194402%21Blank_US_Map.svg" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And a meta-command to rename the file:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true }, "outputs": [], "source": [ "! mv 20091105194402%21Blank_US_Map.svg usa-wikipedia.svg" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "In this example, we want to use the states as before, but also be able to plot longitude and latitude on the map.\n", "\n", "Since the map was just a picture (and not drawn) I wasn't sure what coordinate system it was in.\n", "\n", "After a bit of trial and error, I found that the Albers conic projection was a good fit.\n", "\n", "In this example, I plot some longitude and latitude points, and kept adjusting the xoffset, xscale, yoffset, and yscale until the points lined up pretty well. Normally, we would know these values, but the wikipedia map did not provide those.\n", "\n", "If you click, it will plot those points, and some cites.\n", "\n", "Notice that the albers function returns an array containing the x and the y values:" ] }, { "cell_type": "code", "execution_count": 88, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "